package br.ufrn.findabomb.controller;

import br.ufrn.findabomb.model.Player;
import br.ufrn.findabomb.model.ServerResponse;
import br.ufrn.findabomb.model.ServerResponse.ResponseType;

public class PlayerFinder {
	enum FindMethod {
		PLAYER_ID,
		PLAYER_NAME,
		PLAYER_EMAIL
	}
	/**
	 * Busca e retorna Player no banco de dados remoto, de acordo com os parametros fornecidos
	 * @param name nome que será buscado
	 * @param method método de busca, pode ser por ID, por NAME ou por EMAIL
	 * @return player encontrado, null se não encontrar nenhum
	 */
	public Player findPlayer(String str) {
		ServerResponse sr = ServerFassade.find(Player.class, str);
		if (sr !=null) {
			if (sr.isSuccessfull()) {
				return (Player)sr.getData();
			}
		}
		return null;
	}
	
	public static Player login(String login, String pass) {
		ServerResponse sr = ServerFassade.login(login, pass);
		if (sr!=null && sr.isSuccessfull() && sr.getType()==ResponseType.PLAYER) {
			return (Player)sr.getData();
		}
		return null;
	}
	
}
